<?php

namespace fztadmin\modules\platform\controllers;

use fztadmin\modules\platform\models\forms\LogPlatformCapitalOperation;
use yii\web\Controller;

class CapitalOperationController extends Controller
{
    public function actionCz()
    {
        $fzt = \Yii::$app->fenZhangTong;
        $model = new LogPlatformCapitalOperation();
        $model->type = $model::TYPE_IESI111013;
        $model->plat_no = $fzt->platNo;
        if ($model->load(\Yii::$app->request->post()) && $model->validate()){
            if ($model->cz($fzt)){
                \Yii::$app->session->addFlash("success", "充值成功");
                return $this->redirect(['/platform/capital-operation/cz']);
            }
        }
        return $this->render("cz", ['model' => $model]);
    }

    public function actionTx()
    {
        $fzt = \Yii::$app->fenZhangTong;
        $model = new LogPlatformCapitalOperation();
        $model->type = $model::TYPE_IESI111014;
        $model->plat_no = $fzt->platNo;
        if ($model->load(\Yii::$app->request->post()) && $model->validate()){
            if ($model->cz($fzt)){
                \Yii::$app->session->addFlash("success", "提现成功");
                return $this->redirect(['/platform/capital-operation/tx']);
            }
        }
        return $this->render("tx", ['model' => $model]);
    }

    public function actionTransferOfSelfOwnedFundsBetweenHouseholds()
    {
        $fzt = \Yii::$app->fenZhangTong;
        $model = new LogPlatformCapitalOperation();
        $model->setScenario(LogPlatformCapitalOperation::SCENARIO_TYPE_IESI111015);
        $model->type = $model::TYPE_IESI111015;
        $model->plat_no = $fzt->platNo;
        if ($model->load(\Yii::$app->request->post()) && $model->validate()){
            if ($model->transferOfSelfOwnedFundsBetweenHouseholds($fzt)){
                \Yii::$app->session->addFlash("success", "自有资金分户间转账成功");
                return $this->redirect(['/platform/capital-operation/transfer-of-self-owned-funds-between-households']);
            }
        }
        return $this->render("transfer-of-self-owned-funds-between-households", ['model' => $model]);
    }

    public function actionMemberAccountsTransfer()
    {
        $fzt = \Yii::$app->fenZhangTong;
        $model = new LogPlatformCapitalOperation();
        $model->setScenario(LogPlatformCapitalOperation::SCENARIO_TYPE_IESI111016);
        $model->type = $model::TYPE_IESI111016;
        $model->plat_no = $fzt->platNo;
        if ($model->load(\Yii::$app->request->post()) && $model->validate()){
            if ($model->memberAccountsTransfer($fzt)){
                \Yii::$app->session->addFlash("success", "平台分户转会员分户成功");
                return $this->redirect(['/platform/capital-operation/member-accounts-transfer']);
            }
        }
        return $this->render("member-accounts-transfer", ['model' => $model]);
    }
}